<?php
/**
 * 下载专区
 */
class DownloadApp extends CommonApp {
    //下载专区
    public function indexAct(){
		$result = self::getList('download');
    	self::assign_seo('download');
        //把文件路径中的/用-替换掉，以便文件下载时方便传递下载参数
     	foreach($result['data'] as &$value)
           $value['params']['files'] = str_replace('/', '-', $value['params']['files']);
       	$this->assign('menu',self::menu('download'));
       	$this->assign('result',$result);
       	$this->assign('download',true);
        $this->display('Common/index');
    }
    /**
	 * 附件下载
	 **/
	public function fileDownloadAct(){
	    //下载文件的链接（GET提交过来的file_path字符串要把-替换为/）
		$link = str_replace('-', '/', I('get.file_path'));
		//下载文件绝对路径
		$file_path = PUB_DIR.$link;
		if(!file_exists($file_path))
			$this->ajaxReturn(404,'文件不存在!');
		 //尝试获取附件原文件名
        $file_name = DB('photo')->where("`link`='{$link}'")->cache()->getField('title');
        if($file_name)
            $file_name.=".".File::getSuffix($file_path);
		//附件下载
		File::download($file_path,$file_name);
	}
}